package com.md.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.md.base.BaseRepositoryImpl;
import com.md.domain.model.GoodsType;
import com.md.mapper.GoodsTypeMapper;
import com.md.repository.GoodsTypeRepository;
import org.springframework.stereotype.Repository;

/**
 * @author 刘骄阳
 * 2022-06-12 1:17
 */
@Repository
public class GoodsTypeRepositoryImpl extends BaseRepositoryImpl<GoodsType, GoodsTypeMapper> implements GoodsTypeRepository {

  public GoodsTypeRepositoryImpl(GoodsTypeMapper mapper) {
    super(mapper);
  }

  /**
   * 根据父级id查询子集数量
   *
   * @param parentId 根据父级id,查询子集数量
   * @return 子集数量
   */
  @Override
  public Long selectChildrenCount(final Long parentId) {
    LambdaQueryWrapper<GoodsType> wrapper = new LambdaQueryWrapper<>();
    wrapper.select(GoodsType::getId).eq(GoodsType::getParentId, parentId);
    return mapper.selectCount(wrapper);
  }
}
